/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.demo.jna;

import com.sun.jna.NativeLibrary;

import java.io.IOException;

//import org.vacoor.nothing.web.util.Cookie;
//import org.vacoor.nothing.web.util.SimpleCookie;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-11-18
 * Time: 上午1:01
 * To change this template use File | Settings | File Templates.
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        /*-
        NativeLibrary kernel32 = NativeLibrary.getInstance("Kernel32");
        File file = kernel32.getFile();
        System.out.println(file.getAbsoluteFile());
        Function getPID = kernel32.getFunction("GetCurrentProcessId");
        int pid = getPID.invokeInt(new Object[]{});
        System.out.println(pid);
        */
        /*
        final int None = 0, Ctrl = 2, Shift = 4, Alt = 1, Win = 8;
        NativeLibrary user32 = NativeLibrary.getInstance("user32");
        Function hotKey = user32.getFunction("RegisterHotKey");
        long identifier = 123123;
        int modifier = Alt;
        hotKey.invokeVoid(new Integer[]{1, 1, 1, 1});
        */
//        SimpleCookie jsessionid = new SimpleCookie("JSESSIONID");
//        jsessionid.setDomain("dynamic.12306.cn");
        /*
        String url = "http://www.baidu.com";

        SimpleCookie jsessionid = new SimpleCookie("_javaeye3_session_");
        jsessionid.setDomain("baidu.com");
        jsessionid.setPath("/");
        jsessionid.setMaxAge(600);
        jsessionid.setValue("dsfafas");
        */


//        SimpleCookie web = new SimpleCookie(jsessionid);
//        web.setName("_javaeye_cookie_id_");
//        web.setValue("1384714448586880");

        /*
        NativeLibrary shell32 = NativeLibrary.getInstance("shell32");
        Function f = shell32.getFunction("ShellExecuteA");
        System.out.println(f.invokeInt(new Object[]{
                223,
                "open",
                "iexplore",
                url,
                "",
                1
        }));
        */
//        jsessionid.setMaxAge(0);
//        web.setMaxAge(0);
        /*
        setCookie(url, jsessionid);
        setCookie(url, web);
        */
//        WinReg.HKEY_LOCAL_MACHINE;
    }

    /*- SetIECookie Test */
    /*
    public static void setCookie(String url, Cookie cookie) {

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND, cookie.getMaxAge());
        SimpleDateFormat format = new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss z", Locale.ENGLISH);
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        String expires = format.format(calendar.getTime());

        Object[] params = new Object[]{
                url,
                cookie.getName(),
                cookie.getValue() + "; Domain=" + cookie.getDomain() + "; Path=" + cookie.getPath() + ";expires=" + expires
        };
        System.out.println(Arrays.toString(params));
        Function func = wininet.getFunction("InternetSetCookieA");
        System.out.println(func.invoke(Integer.class, params));
//        Native.loadLibrary()
    }
    */

    static NativeLibrary wininet = NativeLibrary.getInstance("wininet");
}
